package top.mask.mq.dead;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import top.mask.mq.utils.RabbitMQUtil;

import java.util.HashMap;

/**
 * 死信队列实战
 * 消费者1
 */
@Slf4j
public class Consumer02 {


    //死信队列名称
    public static final String DEAD_QUEUE = "dead_queue";

    @SneakyThrows
    public static void main(String[] args) {
        Channel channel = RabbitMQUtil.getChannel();

        log.info("等待接收消息...");

        DeliverCallback deliverCallback = (consumerTag, message) -> {
            log.info("Consumer02死信队列接收到的消息:[{}]", new String(message.getBody(), "UTF-8"));
        };

        CancelCallback cancelCallback = consumerTag ->
                log.info("消息者取消消接口回调逻辑{[]}",consumerTag);
        channel.basicConsume(DEAD_QUEUE,true,deliverCallback,cancelCallback);
    }
}
